<template>
	<div class="appDetails">
		<Card>
			<div class="title">
				详情
			</div>
			<div class="form">
				<label>名称：</label>
				<span>{{name}}</span>
			</div>
			<div class="form">
				<label>命名空间</label>
				<span>{{nameSpace}}</span>
			</div>
			<div class="form">
				<label>标签：</label>
				<span>{{label}}</span>
			</div>
			<div class="form">
				<label>创建时间：</label>
				<span>{{date}}</span>
			</div>
			<div class="form">
				<label>状态：</label>
				<span>{{state}}</span>
			</div>
			<div class="form">
				<label>Qos等级：</label>
				<span>{{Qos}}</span>
			</div>
			<div class="form">
				<label>节点：</label>
				<span>{{node}}</span>
			</div>
			<div class="form">
				<label>IP：</label>
				<span>{{IP}}</span>
			</div>
		</Card>
		<!-- 容器组 -->
		<Card class="myCard">
			<div class="title">
				容器
			</div>
			<div class="form">
				<label>{{containers.name}}</label>
			</div>
			<div class="form">
				<label>镜像：</label>
				<span>{{containers.image}}</span>
			</div>
			<div class="form">
				<label>环境变量：</label>
				<span>-</span>
			</div>
			<div class="form">
				<label>命令：</label>
				<span>-</span>
			</div>
			<div class="form">
				<label>参数：</label>
				<span>-</span>
			</div>
		</Card>
		<!-- 容器组 -->
		<Card class="myCard">
			<div class="title">
				现状
			</div>
			<Table :columns="columns1" :data="tableData1"></Table>
		</Card>
	</div>
</template>

<script>
	export default {
		data () {
			return {
				// 名称
				name: '',
				// 命名空间
				nameSpace: '',
				// 标签
				label: '',
				// 注释
				// notes: '',
				// 时间
				date: '',
				// 策略
				strategy: '',
				// 秒数
				second: '',
				// 历史版本限制值
				history: '',
				// 滚动策略
				overflow: '',
				// 状态
				state: '',
				// qos等级
				Qos: '',
				// 节点
				node: '',
				// ip
				IP: '',
				// label集合
				labelList: [],
				// 容器
				containers: '',
				columns1: [
					{
						title: '类型',
						key: 'type'
					},
					{
						title: '状态',
						key: 'status'
					},
					{
						title: '最近心跳',
						key: '',
						render: (h, params) => {
							return h('div', '-')
						}
					},
					{
						title: '启动时间',
						key: 'lastTransitionTime',
						width: '200px',
						render: (h, params) => {
							var date1 = new Date(params.row.lastTransitionTime).toString().replace(/-/g, '/')
							var date2 = new Date(+new Date(date1) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
							return h('span', date2)
						}
					},
					{
						title: '原因',
						key: '',
						render: (h, params) => {
							return h('div', '-')
						}
					},
					{
						title: '消息',
						key: '',
						render: (h, params) => {
							return h('div', '-')
						}
					}
				],
				tableData1: []
			}
		},
		methods: {
			getDetails () {
				this.$api.get(0, '/kuber/v2/k8s/apps?type=Pod' + '&nameSpace=' + sessionStorage.nameSpace + '&name=' + sessionStorage.name, {}, r => {
					console.log(r.data.data)
					if (r.data.code === 0) {
						let myData = r.data.data
						// 名称
						this.name = myData.metadata.name
						// 命名空间
						this.nameSpace = myData.metadata.namespace
						// 标签
						this.label = myData.metadata.labels
						// 时间
						this.date = myData.metadata.creationTimestamp
						// 状态
						this.state = myData.status.phase
						// qos等级
						this.Qos = myData.status.qosClass
						// 节点
						this.node = myData.spec.nodeName
						// ip
						this.IP = myData.status.podIP
						for (var item in myData.metadata.labels) {
							this.labelList.push({'name': item, 'value': myData.metadata.labels[item]})
						}
						// 容器
						this.containers = myData.spec.containers[0]
						this.tableData1 = myData.status.conditions
					}
				})
			}
		},
		mounted () {
			this.getDetails()
		}
	}
</script>
